package com.sky.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.mapper.EmployeeMapper;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class CategoryServicelmpl implements CategoryService {


    @Autowired
    private EmployeeMapper employeeMapper;

    @Override
    public Result inquireCategory(CategoryPageQueryDTO categoryPageQueryDTO) {
        //非空判断
        if (categoryPageQueryDTO.getPage()==null){
            return Result.error("404");
        }
        if (categoryPageQueryDTO.getPageSize()==null){
            return Result.error("404");
        }

        PageHelper.startPage(categoryPageQueryDTO.getPage(), categoryPageQueryDTO.getPageSize());
        //调用mapper获取数据
        Page<Category> category = employeeMapper.inquireCategory(categoryPageQueryDTO);

        //开启分页查询

//        将参数传入进工具种
        PageResult pageResult=new PageResult();
        pageResult.setTotal(category.getTotal());
        pageResult.setRecords(category.getResult());

        //返回数据
        return Result.success(pageResult);

    }
}
